package edu.rpi.semantic.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileUtils {

	
	public static void copyFile(String from, String to) throws IOException {
		File fromFile = new File(from);
		File toFile = new File(to);
		if (!fromFile.exists()) {
			Log.err("fromFile: " + from + " does not exist!");
			throw new IOException("can't read!");
		}

		if (toFile.exists()) {
			Log.err("toFile: " + to + " exist!");
			throw new IOException("can't write!");
		}

		FileInputStream input = new FileInputStream(fromFile);
		FileOutputStream output = new FileOutputStream(toFile);
		byte[] b = new byte[1024 * 5];
		int len;
		while ((len = input.read(b)) != -1) {
			output.write(b, 0, len);
		}
		
		output.flush();
		output.close();
		input.close();

	}
}
